package pub.xspace.nova.system.controller;

import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import pub.xspace.nova.common.controller.BaseController;
import pub.xspace.nova.common.domain.AjaxResult;
import pub.xspace.nova.system.domain.SysOrg;
import pub.xspace.nova.system.service.SysOrgService;

@RestController
@RequestMapping("/system/org")
public class SysOrgController extends BaseController {

	@Resource
	private SysOrgService sysOrgService;

	@PostMapping("/getTreeList")
	public AjaxResult getTreeList() {
		return success(sysOrgService.getTreeData());
	}

	@PostMapping("/save")
	public AjaxResult save(@RequestBody SysOrg sysOrg) {
		sysOrg.setCreateUser("admin");
		sysOrgService.save(sysOrg);
		return success();
	}

	@PutMapping("/update")
	public AjaxResult update(@RequestBody SysOrg sysOrg) {
		sysOrg.setUpdateUser("admin");
		sysOrgService.updateById(sysOrg);
		return success(sysOrg);
	}

	@DeleteMapping("/deleteById")
	public AjaxResult deleteById(String id) {
		sysOrgService.deleteById(id);
		return success();
	}

	@DeleteMapping("/deleteByIds")
	public AjaxResult deleteByIds(@RequestBody List<String> ids) {
		sysOrgService.deleteByIds(ids);
		return success();
	}
}
